<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="cn.myschool.entity.Student" %>
<%@ page import="java.util.List" %>
<%@ page import="cn.myschool.service.StudentService" %>
<%@ page import="cn.myschool.util.StrUtil" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="cn.myschool.entity.Grade" %>
<%@ page import="cn.myschool.service.GradeService" %>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>超市账单管理系统</title>
    <link rel="stylesheet" href="css/public.css"/>
    <link rel="stylesheet" href="css/style.css"/>
    <script src="js/jquery.js"></script>

</head>
<body>
<!--主体内容-->
<section class="publicMian">
    <div class="right">
        <div class="location">
            <strong>你现在所在的位置是:</strong>
            <span>学生管理</span>
        </div>
        <%
            List<Student> datas = new ArrayList<>();

            String sname=request.getParameter("sname");
            String qq=request.getParameter("qq");

            sname=sname==null?"":sname;
            qq=qq==null?"":qq;

            int pageNo= StrUtil.toInt(request.getParameter("pageNo"),1);
            datas = StudentService.ME.paging(0, null, sname, qq, null, null,pageNo,10);

        %>
        <div class="search">
            <form action="student.jsp" method="get" id="seachForm">
                <input type="hidden" name="pageNo" id="pageNo" value="<%=pageNo%>"/>
                <span>学生名：</span>
                <input type="text" name="sname" value="<%=sname%>" placeholder="姓名" />
                <input type="text" name="qq" value="<%=qq%>" placeholder="qq"/>
                <input type="submit" value="查询" class="form"/>
            </form>
            <a href="studentAdd.jsp">添加</a>
        </div>
        <!--供应商操作表格-->
        <table class="providerTable" cellpadding="0" cellspacing="0">
            <tr class="firstTr">
                <th width="10%">学号</th>
                <th width="15%">姓名</th>
                <th width="10%">性别</th>
                <th width="10%">年级</th>
                <th width="10%">地址</th>
                <th width="10%">手机号</th>
                <th width="30%">操作</th>
            </tr>
            <%
                for (Student s : datas) {
            %>
            <tr>
                <td><%=s.getStuno()%>
                </td>
                <td><%=s.getSname()%>
                </td>
                <td><%=s.getSex()%>
                </td>
                <td>
                    <%
                        List<Grade> grades = GradeService.ME.findALL();
                        for (Grade grade :grades) {
                            String gname = grade.getGname();
                            long sid = grade.getId();
                            if(s.getGradeid()==sid){
                    %>
                   <%=gname%>
                    <%
                            }
                        }
                    %>
                </td>
                <td><%=s.getAddress()%>
                </td>
                <td><%=s.getTelephone()%>
                </td>
                <td>
                    <a href="providerView.html"><img src="img/read.png" alt="查看" title="查看"/></a>
                    <a href="studentUpdate.jsp?id=<%=s.getStuno()%>"><img src="img/xiugai.png" alt="修改" title="修改"/></a>
                    <a href="studentremove.jsp?id=<%=s.getStuno()%>" onclick="return window.confirm('是否确认删除')"
                       class="removeProvider"><img src="img/schu.png" alt="删除" title="删除"/></a>
                </td>
            </tr>
            <%}%>
        </table>
        <p align="center" class="pager">
            <%
                if(pageNo>1){
            %>
            <a id="prev" href="#" data-page="<%=pageNo-1%>">上一页</a>
            <%}%>
            <a href="#" id="next" data-page="<%=pageNo+1%>">下一页</a>

        </p>
    </div>
</section>

<script>
    $(function () {
        $("form#seachForm :submit").click(function () {
            $("#pageNo").val(1);//每次搜索，页号从1开始
            return true;
        });
        $(".pager a#prev,.pager a#next").click(function () {
            let pageNo= $(this).data("page");
            //alert(pageNo);
            //$(this).attr("data-page");
            $("#pageNo").val(pageNo);
            $("form#seachForm").submit();//手工提交表单
            return false;//让a 链接失效
        });
    });
</script>

</body>
</html>